<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewReportTransfer extends JView
{
	function display($tpl=null) {

		global $mainframe;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');
		
		//Check access
		if($user->gid < 25) {
			if ( !(Ownservice::checkAccess('printreport', 'manage')) ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}

		if($this->getLayout() == 'todayreport')
		{
			$this->_displaytodayreport($tpl);
			return;
		}

		if($this->getLayout() == 'monthlyreport')
		{
			$this->_displaymonthlyreport($tpl);
			return;
		}

		if($this->getLayout() == 'details')
		{
			$this->_displaydetails($tpl);
			return;
		}

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//assign data to document
			
		parent::display($tpl);
	}

	function _displaytodayreport($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document		= & JFactory::getDocument();
		$config			= & JFactory::getConfig();
		$user				= & JFactory::getUser();
		$params 		= & $mainframe->getParams('com_ownservice');
		$pathway  		= & $mainframe->getPathway();
		

		//Check access
		if($user->gid < 25) {
			if ( !(Ownservice::checkAccess('printreport', 'manage')) ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}

		//Set page title information
		$menus			= &JSite::getMenu();
		$menu			= $menus->getActive();

		//$tzoffset			=$config->getValue('config.offset');
	 	//$date 			=& JFactory::getDate($dateAndTime, 10);

		//get date time now
		//$now						= $date->toMySQL();
		$now						= date('Y-m-d H:i:s');
		list($dateA, $timeA)	= explode(' ', $now);

		//get var
		$day						= JRequest::getVar('date', $dateA, 'post','string');

		$selectday				= $day;
		
		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$model	= $this->getModel();
		$rows		= $model->getTodays($selectday);

		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_TODAY_REPORT'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_TODAY_REPORT'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('reportdate', $selectday);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}

	function _displaymonthlyreport($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document		= & JFactory::getDocument();
		$config			= & JFactory::getConfig();
		$user			= & JFactory::getUser();
		$params 		= & $mainframe->getParams('com_ownservice');
		$pathway  		= & $mainframe->getPathway();
		
		//Check access
		if($user->gid < 25) {
			if ( !(Ownservice::checkAccess('printreport', 'manage')) ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}

		//Set page title information
		$menus			= &JSite::getMenu();
		$menu			= $menus->getActive();
	
		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$model	= $this->getModel();
		$rows		= $this->get("Monthlyreport");

		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_MONTHLY_REPORT'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_MONTHLY_REPORT'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		$unix1	= mktime(date("H"),date("i"),date("s"),date("n")-1,1,date("Y"));

		 $l_m		= date('m', $unix1);
		 $l_y		= date('Y', $unix1);

		if((int) date("d")  <= 10) {
			$date = $l_y.'-'.$l_m.'-1'.' '.JText::_('OWNSERVICE_TO').' '.date("Y").'-'.date("m").'-'.date("d");
		} else {
			$date = date("Y").'-'.date("m").'-1'.' '.JText::_('OWNSERVICE_TO').' '.date("Y").'-'.date("m").'-'.date("d");
		}

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('date', $date);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}

	function _displaydetails($tpl)
	{
		global $mainframe;

		//Initialize variables
		$document		= & JFactory::getDocument();
		$config			= & JFactory::getConfig();
		$user				= & JFactory::getUser();
		$params 		= & $mainframe->getParams('com_ownservice');
		$pathway  		= & $mainframe->getPathway();

		//Check access
		if($user->gid < 25) {
			if ( !(Ownservice::checkAccess('printreport', 'manage')) ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect( 'index.php?option=com_ownservice');
			}
		}
		
		//Set page title information
		$menus			= &JSite::getMenu();
		$menu			= $menus->getActive();

		//get vars
		$session			= JRequest::getVar('session', 0, 'post', 'int');
		$date				= JRequest::getVar('date', '', 'post');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//get data from the model
		$model	=& $this->getModel();
		$rows		= $this->get('DetailTransfer');

		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_DETAIL_TRANSFER'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_DETAIL_TRANSFER'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('reportdate', $date);
		$this->assignRef('session', $session);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}
}